package com.gjy.datetime;

import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-03-08 17:38:26
 */
public class TimeTest {

    @Test
    public void test3() {
        // 获取当前月份的第一天
        LocalDate firstDay = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
        System.out.println("当前月份的第一天：" + firstDay);

        // 获取当前月份的最后一天
        LocalDate lastDay = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
        System.out.println("当前月份的最后一天：" + lastDay);

        // 获取当前天的最小时间和最大时间
        LocalDate today = LocalDate.now();
        System.out.println("当前天的最小时间：" + today.atStartOfDay());
        System.out.println("当前天的最大时间：" + today.atTime(23, 59, 59, 999999999));
    }

    @Test
    public void test4() {
        DateTime dateTime = new DateTime();
        System.out.println("dateTime.millisOfDay().withMinimumValue() = " + dateTime.millisOfDay().withMinimumValue());
        System.out.println("dateTime.millisOfDay().withMaximumValue() = " + dateTime.millisOfDay().withMaximumValue());
    }


    @Test
    public void test2() {
        long time = new Date().getTime();
        System.out.println("time = " + time);
    }

    @Test
    public void test1() {
        String day = "2023-3-9";
        LocalDate parse = LocalDate.parse(day, DateTimeFormatter.ofPattern("yyyy-M-d"));
        System.out.println("parse = " + parse);
    }
}
